/**
 * 文件名：NutritionFacts.java
 * 
 * 版本信息：
 * 日期：2017-6-9
 * Copyright 足下 Corporation 2017
 * 版权所有
 * 
 */
package com.sam.builder;

/**
 * <b>项目名称</b>：effectiveJava<br>
 * <b>类名称</b>：类的实例化builder模式NutritionFacts<br>
 * <b>类描述</b>：<br>
 * <b>创建人</b>：SAM QZL<br>
 * <b>创建时间</b>：2017-6-9 下午4:07:39<br>
 * <b>修改人</b>：SAM QZL<br>
 * <b>修改时间</b>：2017-6-9 下午4:07:39<br>
 * <b>修改备注</b>：<br>
 * @author SAM QZL<br>
 * @version
 * 
 */
public class NutritionFacts {

    private final int servingSize;
    private final int servings;
    private final int calories;
    private final int fat;
    private final int sodium;
    private final int carbohydrate;

    public static class Builder {

        /** 必要参数 **/
        private final int servingSize;
        private final int servings;
        /** 可选参数 初始化默认值 **/
        private int calories = 0;
        private int fat = 0;
        private int carbohydrate = 0;
        private int sodium = 0;

        public Builder(int servingSize, int servings) {

            this.servingSize = servingSize;
            this.servings = servings;
        }

        public Builder calories(int val) {

            calories = val;
            return this;
        }

        public Builder fat(int val) {

            fat = val;
            return this;
        }

        public Builder carbohydrate(int val) {

            carbohydrate = val;
            return this;
        }

        public Builder sodium(int val) {

            sodium = val;
            return this;
        }

        public NutritionFacts build() {

            return new NutritionFacts(this);
        }
    }

    private NutritionFacts(Builder bulider) {

        servingSize = bulider.servingSize;
        servings = bulider.servings;
        calories = bulider.calories;
        fat = bulider.fat;
        sodium = bulider.sodium;
        carbohydrate = bulider.carbohydrate;
    }

    public int getServingSize() {

        return servingSize;
    }

    public int getServings() {

        return servings;
    }

    public int getCalories() {

        return calories;
    }

    public int getFat() {

        return fat;
    }

    public int getSodium() {

        return sodium;
    }

    public int getCarbohydrate() {

        return carbohydrate;
    }

    public static void main(String args[]) {

        NutritionFacts butritionFacts = new NutritionFacts.Builder(25, 32).fat(10).build();
        System.out.println(butritionFacts.toString());
    }
}
